package PatternOfDesign.Singleton;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Ghost on 2015/3/4 0004.
 */
public class SimpleFactory {
    public static void main(String[] args){
        List<Animale> zoo = new ArrayList<Animale>();
        for(int i=0;i<4;i++)
            zoo.add(AnimalFactory.getAnimale(0));
        for(int i=0;i<2;i++)
            zoo.add(AnimalFactory.getAnimale(1));
        for(int i=0;i<4;i++)
            zoo.add(AnimalFactory.getAnimale(2));
        for(int i=0;i<2;i++)
            zoo.add(AnimalFactory.getAnimale(3));

        for(Animale animale:zoo){
            //animale....
        }
    }
}
interface Animale{
    public abstract void shout();
}

class DGoat implements Animale{

    @Override
    public void shout() {
        System.out.println("goat shout");
    }
}

class DChicken implements Animale{

    @Override
    public void shout() {
        System.out.println("chicken shout");
    }
}
class DDog implements Animale{

    @Override
    public void shout() {
        System.out.println("dog shout");
    }
}

class DCat implements Animale{

    @Override
    public void shout() {
        System.out.println("cat shout");
    }
}

class AnimalFactory{

    public static Animale getAnimale(int kind){
        Animale animale = null;
        switch(kind){
            case 0:
                animale = new DDog();
                break;
            case 1:
                animale = new DCat();
                break;
            case 2:
                animale = new DGoat();
                break;
            case 3:
                animale = new DChicken();
                break;
            default:
                animale = null;
        }
        return animale;
    }
}



